/**
 * 	
 *  Copyright(c) 2009: Mantecao / Grupo Alion C.A.
 *  url: www.mantecao.com.ve/licensing
 *  email: licensing@mantecao.com.ve   
 *  author: Nilda Ching
 * 
 */
 
 _IG_RegisterOnloadHandler(loadDependencies); 
var width_rotator;
// Get userprefs
var prefs = new _IG_Prefs(); //gadgets.Prefs();

function loadDependencies(){
	width_rotator =  prefs.getString('width');//$("table.gadget").context.width;//$("table.gadget").context.width - 90;
		
	$("div.scrollable").css('width', width_rotator);
	google.setOnLoadCallback(init); 
}

function init(){ 
	//var url = URL + "api/private/products/base.json?opt=complete&classification=15"; 
		
	var url = config.variants.gadget;
	var params = {}; 
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; 
	gadgets.io.makeRequest(url, handle_response, params); 
}

function handle_response(obj){ 
	var i = 0;
	$.each(obj.data.response.entry,function(i, item){
		var div = $('<div id="promo' + i + '" style="float:left;"></div>');
		var table = $('<table style="width:100%; margin-left:auto;margin-right:auto;"></table>');
		var tr = $("<tr></tr>");
		tr.append('<td><img src="'+ config.env[env]['site'] + item.product.images[0].public_filename + '"/></td>');
		tr.append('<td style="vertical-align:top;text-align:right;"><h5>' + item.product.name + '</h5><br/><span class="price1">&nbsp;&nbsp;&nbsp;' + config.variants.formatCurrency + '&nbsp;' + item.product.price.base + '&nbsp;&nbsp;</span><br/><span class="price2">' + app.labels.marketPrice + config.variants.formatCurrency + '&nbsp;' + item.product.price.market + '&nbsp;&nbsp;</span><br/><span class="price3">' + app.labels.storePrice + config.variants.formatCurrency + '&nbsp;' + item.product.price.store + '&nbsp;&nbsp;</span></td>');
		table.append(tr);
		div.append(table);
		$("div.items").append(div);
		i+=1;
	});
	
    $("div","div.items").css('width', width_rotator);
	
	// initialize scrollable 
	$("div.scrollable").scrollable({
		size : parseInt(prefs.getString('sizeproducts'))
	}).circular();
	
}